package schoolWork.work02;

public class CashRegister {
    //定义成员变量
    private double purchase;    //总销售额
    private double payment;     //付款金额
    private String history;     //购买的商品价格清单
    private static double salesTotal = 0;
    private static int salesCount = 0;

    //定义构造方法
    public CashRegister() {
        purchase = 0;
        payment = 0;
        history = "";

    }

    //定义要用的方法
    public void recordPurchase(double amount) {
        purchase = purchase + amount;

        salesTotal = salesTotal + amount;
        salesCount++;
        //将购买的每一个商品价格记录在字符串history当中
        history = history + String.valueOf(amount) + "\n";
    }

    public void receivePayment(double amount) {
        payment = payment + amount;
    }

    public double giveChange() {
        double change = payment - purchase;
        purchase = 0;
        payment = 0;
        history = "";
        return change;
    }

    public void printReceipt() {
        System.out.println("List:\n" + history);
        System.out.println("Total:" + String.valueOf(purchase));
    }

    public static void reset() {
        salesTotal = 0;
        salesCount = 0;
    }
}
